package org.jeecg.dc.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.dc.model.CollectorMapperDto;
import org.jeecg.dc.model.FileDto;
import org.jeecg.dc.service.CollectParser;
import org.jeecg.modules.demo.hydrology.entity.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
public class SwjcParser extends CollectParser {

    public SwjcParser(CollectorMapperDto mapperDto, final Charset charset) {
        mapper = mapperDto;
        this.charset = charset;
    }

    @Override
    public void parse(final List<FileDto> files) {
        Stream.of((Consumer<List<FileDto>>) this::analyzeCddyFile,
                this::analyzeCdssFile,
                this::analyzeCdycFile
        ).parallel().forEach(a -> tryAnalyze(a, files));

    }

    protected String getFileNameRegex(final String type) {
        return String.join("", "(\\d+)_", type, "_(\\d{14}).txt");
    }

    protected String getDatum(String[] data, int index) {
        if (data == null || data.length <= index) {
            log.warn("null[{}]: {}", data, index);
            return null;
        }
        String datum = data[index];
        if (!StringUtils.hasText(datum)) {
            log.warn("empty[{}]: {}", data, index);
        }
        return datum.trim();
    }

    protected BigDecimal getDecimal(String[] data, int index) {
        Logger log = LoggerFactory.getLogger(this.getClass());
        if (data == null || data.length <= index || data[index] == null) {
            log.warn("Invalid data or index: data = {}, index = {}", data, index);
            return null;
        }

        String datum = data[index].trim();
        if (!StringUtils.hasText(datum)) {
            log.warn("Empty value at index {}: data = {}", index, data);
            return null;
        }

        try {
            // 将字符串转换为 Decimal
            BigDecimal value = new BigDecimal(datum);
            return value;
        } catch (NumberFormatException e) {
            log.warn("Failed to convert value at index {}: data = {}", index, data, e);
            return null;
        }
    }
    private String getType(final String type) {
        if (type == null) {
            return "其它类型";
        }
        switch (type) {
            case "0501":
                return "降水量";
            case "0502":
                return "水位";
            case "0507":
                return "水温";
            case "0503":
                return "涌水量";
            case "0504":
                return "排水量";
            case "0505":
                return "地表沉陷位移";
            case "0506":
                return "疏（放）水量";
            case "0607":
                return "微震（水文）";
        }
        return "其它类型";
    }
    private String getUnit(final String type) {
        if (type == null) {
            return "";
        }
        switch (type) {
            case "0501":
                return "mm";
            case "0502":
                return "m";
            case "0507":
                return "℃";
            case "0503":
                return "m³/h";
            case "0504":
                return "m³/h";
            case "0505":
                return "";
            case "0506":
                return "m³/h";
            case "0607":
                return "";
        }
        return "";
    }
    private String getStatus(final String status) {
        if (status == null) {
            return "";
        }
        switch (status) {
            case "00000000":
                return "正常";
            case "00000001":
                return "报警";
            case "00000010":
                return "未知";
            case "00000100":
                return "分站故障";
            case "00001000":
                return "传感器故障";
            case "00010000":
                return "蓝色预警";
            case "001000000":
                return "黄色预警";
            case "01000000":
                return "橙色预警";
            case "1000000":
                return "红色预警";
        }
        return "";
    }

    private String getLevel(final String level) {
        if (level == null) {
            return "";
        }
        switch (level) {
            case "1":
                return "红";
            case "2":
                return "橙";
            case "3":
                return "黄";
            case "4":
                return "蓝";
        }
        return "";
    }
    private void analyzeCddyFile(List<FileDto> FileDtos) {
        List<FileDto> FileDto = FileDtos.stream()
                .filter(f -> StringUtils.hasLength(f.getFileName()) && f.getFileName().length() > 18)
                .sorted(Comparator.comparing(f -> f.getFileName().substring(f.getFileName().length() - 18)))
                .collect(Collectors.toList());

        Stream.of((Consumer<List<FileDto>>) this::analyzeCgkCddy,
                this::analyzeJslCddy,
                this::analyzePslCddy,
                this::analyzeYslCddy,
                this::analyzeDbcxCddy,
                this::analyzeCsCddy,
                this::analyzeDbsCddy,
                this::analyzeWzCddy
        ).parallel().forEach(a -> tryAnalyze(a, FileDto));
    }
    protected void analyzeWzCddy(List<FileDto> fileInfos) {
        analyze("WZCDDY",fileInfos,this::analyzeWzCddy);
    }

    private void analyzeWzCddy(List<String> matches, String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;
        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留

                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    // 检查第二个部分的字段数量
                    if (data.length < 10) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid data: {}", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String name = getDatum(data, 1);
                    String no = getDatum(data, 2);
                    String length = getDatum(data, 3);
                    String fre = getDatum(data, 4);
                    String direct = getDatum(data, 5);
                    String mode = getDatum(data, 6);
                    BigDecimal sens = getDecimal(data, 7);
                    String type = getDatum(data, 8);
                    String location = getDatum(data, 9);
                    BigDecimal x = getDecimal(data, 10);
                    BigDecimal y = getDecimal(data, 11);
                    BigDecimal z = getDecimal(data, 12);
                    String date = getDatum(data, 13);
                    Wzcddy cd = new Wzcddy();
                    if (no != null) {
                        int t = Integer.parseInt(no);
                        cd.setRecordChannelNo(t);
                    }
                    if (length != null) {
                        int t = Integer.parseInt(length);
                        cd.setSamplingLength(t);
                    }
                    if (fre != null) {
                        int t = Integer.parseInt(fre);
                        cd.setSamplingFrequency(t);
                    }
                    if (date != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        date1 = sdf.parse(date);
                        cd.setInstallationDate(date1);
                    }
                    cd.setStationCode(code);
                    cd.setEquipmentPosition(location);
                    cd.setRegionName(name);
                    cd.setSensorDirection(direct);
                    cd.setSensorType(type);
                    cd.setInstallationMode(mode);
                    cd.setSensitivity(sens);
                    cd.setCoordinateX(x);
                    cd.setCoordinateY(y);
                    cd.setCoordinateZ(z);
                    cd.setStationMine(mineCode);
                    QueryWrapper<Wzcddy> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code", cd.getStationCode());
                    Wzcddy wzcddy = mapper.getWzcddyService().getOne(queryWrapper);
                    if (wzcddy != null) {
                        cd.setId(wzcddy.getId());
                        mapper.getWzcddyService().updateById(cd);
                    } else {
                        mapper.getWzcddyService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }

        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeDbsCddy(List<FileDto> fileInfos) {
        analyze("DBSCDDY",fileInfos,this::analyzeDbsCddy);
    }

    private void analyzeDbsCddy(List<String> matches, String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;
        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留

                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    // 检查第二个部分的字段数量
                    if (data.length < 10) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid data: {}", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String type = getDatum(data, 1);
                    String location = getDatum(data, 2);
                    String installationDate = getDatum(data, 3);
                    String manu = getDatum(data, 4);
                    String inspectionTime = getDatum(data, 5);
                    String sensor = getDatum(data, 6);
                    String unit = getDatum(data, 7);
                    BigDecimal x = getDecimal(data, 8);
                    BigDecimal y = getDecimal(data, 9);
                    BigDecimal z = getDecimal(data, 10);
                    Dbscddy cd = new Dbscddy();
                    if (type != null) {
                        int t = Integer.parseInt(type);
                        cd.setEquipmentType(t);
                    }
                    if (installationDate != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        date1 = sdf.parse(installationDate);
                        cd.setInstallationDate(date1);
                    }
                    if (inspectionTime != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        date1 = sdf.parse(inspectionTime);
                        cd.setInspectionDate(date1);
                    }
                    cd.setStationCode(code);
                    cd.setEquipmentPosition(location);
                    cd.setUnit(unit);
                    cd.setManufacturer(manu);
                    cd.setSensorType(sensor);
                    cd.setCoordinateX(x);
                    cd.setCoordinateY(y);
                    cd.setCoordinateZ(z);
                    cd.setStationMine(mineCode);

                    QueryWrapper<Dbscddy> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code", cd.getStationCode());
                    Dbscddy dbscddy = mapper.getDbscddyService().getOne(queryWrapper);
                    if (dbscddy != null) {
                        cd.setId(dbscddy.getId());
                        mapper.getDbscddyService().updateById(cd);
                    } else {
                        mapper.getDbscddyService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }

        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeCsCddy(List<FileDto> fileInfos) {
        analyze("CSCDDY",fileInfos,this::analyzeCsCddy);
    }

    private void analyzeCsCddy(List<String> matches, String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;
        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留

                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    // 检查第二个部分的字段数量
                    if (data.length < 12) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid data: {}", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String location = getDatum(data, 1);
                    String unit = getDatum(data, 2);
                    String level = getDatum(data, 3);
                    BigDecimal th = getDecimal(data, 4);
                    BigDecimal depth = getDecimal(data, 5);
                    BigDecimal hole = getDecimal(data, 6);
                    BigDecimal aperture = getDecimal(data, 7);
                    BigDecimal x = getDecimal(data, 8);
                    BigDecimal y = getDecimal(data, 9);
                    BigDecimal z = getDecimal(data, 10);
                    BigDecimal coe = getDecimal(data, 11);
                    String date = getDatum(data, 12);
                    Cscddy cd = new Cscddy();
                    if (date != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        date1 = sdf.parse(date);
                        cd.setDataTime(date1);
                    }
                    cd.setStationCode(code);
                    cd.setEquipmentPosition(location);
                    cd.setUnit(unit);
                    cd.setWaterLayerLevel(level);
                    cd.setWaterLayerThickness(th);
                    cd.setWaterLayerDepth(depth);
                    cd.setHoleDepth(hole);
                    cd.setAperture(aperture);
                    cd.setCoordinateX(x);
                    cd.setCoordinateY(y);
                    cd.setCoordinateZ(z);
                    cd.setPermeabilityCoefficient(coe);
                    cd.setStationMine(mineCode);
                    QueryWrapper<Cscddy> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code", cd.getStationCode());
                    Cscddy cscddy = mapper.getCscddyService().getOne(queryWrapper);
                    if (cscddy != null) {
                        cd.setId(cscddy.getId());
                        mapper.getCscddyService().updateById(cd);
                    } else {
                        mapper.getCscddyService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }

        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeDbcxCddy(List<FileDto> fileInfos) {
        analyze("DBCXCDDY",fileInfos,this::analyzeDbcxCddy);
    }

    protected void analyzeCgkCddy(final List<FileDto> fileInfos) {
        analyze("CGKCDDY", fileInfos, this::analyzeCgkCddy);
    }

    private void analyzeDbcxCddy(List<String> matches, String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;
        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留

                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    // 检查第二个部分的字段数量
                    if (data.length < 10) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid data: {}", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String name = getDatum(data, 1);
                    BigDecimal depth = getDecimal(data, 2);
                    BigDecimal area = getDecimal(data, 3);
                    String bound = getDatum(data, 4);
                    String method = getDatum(data, 5);
                    String pile = getDatum(data, 6);
                    BigDecimal x = getDecimal(data, 7);
                    BigDecimal y = getDecimal(data, 8);
                    BigDecimal z = getDecimal(data, 9);
                    String date = getDatum(data, 10);
                    Dbcxcddy cd = new Dbcxcddy();
                    if (date != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        date1 = sdf.parse(date);
                        cd.setInstallationDate(date1);
                    }
                    cd.setStationCode(code);
                    cd.setRegionName(name);
                    cd.setMiningDepth(depth);
                    cd.setRegionArea(area);
                    cd.setAreaBoundary(bound);
                    cd.setMiningMethod(method);
                    cd.setPileCode(pile);
                    cd.setCoordinateX(x);
                    cd.setCoordinateY(y);
                    cd.setCoordinateZ(z);
                    cd.setStationMine(mineCode);
                    QueryWrapper<Dbcxcddy> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code",cd.getStationCode());
                    Dbcxcddy dbcxcddy = mapper.getDbcxcddyService().getOne(queryWrapper);
                    if (dbcxcddy != null){
                        cd.setId(dbcxcddy.getId());
                        mapper.getDbcxcddyService().updateById(cd);
                    }else {
                        mapper.getDbcxcddyService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }

        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }


    private void analyzeCgkCddy(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;
        String[] lines = content.split("\\|\\|");

            for (String line : lines) {
                try {
                    String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留

                    if (parts.length < 2) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid line: {}", line);
                        continue;
                    }
                    for (int i = 1; i < parts.length; i++) {
                        // 第一个部分处理
                        String[] mines = parts[0].split(";");
                        String mineCode = getDatum(mines,0);
                        // 第二个部分使用 ';' 分割
                        String[] data = parts[i].split(";");
                        // 检查第二个部分的字段数量
                        if (data.length < 10) {
                            // 如果字段数量不足，跳过该行
                            log.warn("Invalid data: {}", line);
                            continue;
                        }
                        long start = System.currentTimeMillis();
                        String code = getDatum(data, 0);
                        String type = getDatum(data, 1);
                        if (type != null){
                            type = getType(type);
                        }
                        String location = getDatum(data, 2);
                        String level = getDatum(data, 3);
                        BigDecimal hight = getDecimal(data, 4);
                        BigDecimal deep = getDecimal(data, 5);
                        BigDecimal holeDeep = getDecimal(data, 6);
                        BigDecimal holeD = getDecimal(data, 7);
                        BigDecimal x = getDecimal(data, 8);
                        BigDecimal y = getDecimal(data, 9);
                        BigDecimal z = getDecimal(data, 10);
//                    String levelBlue = getDatum(data, 11);
//                    String levelYellow = getDatum(data, 12);
//                    String levelOrange = getDatum(data, 13);
//                    String levelRed = getDatum(data, 14);
//                    BigDecimal temperatureBlue = getDecimal(data, 15);
//                    BigDecimal temperatureYellow = getDecimal(data, 16);
//                    BigDecimal temperatureOrange = getDecimal(data, 17);
//                    BigDecimal temperatureRed = getDecimal(data, 18);
                        String date = getDatum(data, 11);
                        Cgkcddy cd = new Cgkcddy();
                        if (date != null){
                            Date date1 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            date1 = sdf.parse(date);
                            cd.setInstallationDate(date1);
                        }
                        cd.setStationCode(code);
                        cd.setSensorType(type);
                        cd.setEquipmentPosition(location);
                        cd.setWaterLayerLevel(level);
                        cd.setWaterLayerThickness(hight);
                        cd.setWaterLayerDepth(deep);
                        cd.setDrillName(location + "长观孔" + type);
                        cd.setHoleDepth(holeDeep);
                        cd.setAperture(holeD);
                        cd.setCoordinateX(x);
                        cd.setCoordinateY(y);
                        cd.setCoordinateZ(z);
//                    cd.setWaterLevelWarningBlue(levelBlue);
//                    cd.setWaterLevelWarningYellow(levelYellow);
//                    cd.setWaterLevelWarningOrange(levelOrange);
//                    cd.setWaterLevelWarningRed(levelRed);
//                    cd.setWaterTemperatureWarningBlue(temperatureBlue);
//                    cd.setWaterTemperatureWarningYellow(temperatureYellow);
//                    cd.setWaterTemperatureWarningOrange(temperatureOrange);
//                    cd.setWaterTemperatureWarningRed(temperatureRed);
                        cd.setStationMine(mineCode);
                        QueryWrapper<Cgkcddy> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("station_code",cd.getStationCode());
                        Cgkcddy cgkcddy = mapper.getCgkcddyService().getOne(queryWrapper);
                        if (cgkcddy != null){
                            cd.setId(cgkcddy.getId());
                            mapper.getCgkcddyService().updateById(cd);
                        }else {
                            mapper.getCgkcddyService().save(cd);
                        }
                        log.info("cost:" + (System.currentTimeMillis() - start));

                        count++;
                    }

                } catch (Exception e) {
                    log.warn("", e);
                    log.warn("analyze_fail:[{}]", line);
                }
        }

        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }


    protected void analyzeJslCddy(final List<FileDto> fileInfos) {
        analyze("JSLCDDY", fileInfos, this::analyzeJslCddy);
    }
    private void analyzeJslCddy(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;
        String[] lines = content.split("\\|\\|");

            for (String line : lines) {
                try {
                    String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留

                    if (parts.length < 2) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid line: {}", line);
                        continue;
                    }
                    for (int i = 1; i < parts.length; i++) {
                        // 第一个部分处理
                        String[] mines = parts[0].split(";");
                        String mineCode = getDatum(mines, 0);
                        // 第二个部分使用 ';' 分割
                        String[] data = parts[i].split(";");
                        if (data.length < 8) {
                            log.info("data_invalid: [{}]", line);
                            continue;
                        }
                        long start = System.currentTimeMillis();
                        String code = getDatum(data, 0);
                        String type = getDatum(data, 1);
                        String location = getDatum(data, 2);
                        String date = getDatum(data, 3);
                        String fact = getDatum(data, 4);
                        String date2 = getDatum(data, 5);
                        BigDecimal x = getDecimal(data, 6);
                        BigDecimal y = getDecimal(data, 7);
                        BigDecimal z = getDecimal(data, 8);
                        Jslcddy cd = new Jslcddy();
                        if (date != null) {
                            Date date1 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            date1 = sdf.parse(date);
                            cd.setInstallationDate(date1);
                        }
                        if (date2 != null) {
                            Date date3 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            date3 = sdf.parse(date2);
                            cd.setInspectionDate(date3);
                        }
                        cd.setStationMine(mineCode);
                        cd.setStationCode(code);
                        cd.setEquipmentPosition(location);
                        cd.setEquipmentType(type);
                        cd.setManufacturer(fact);
                        cd.setCoordinateX(x);
                        cd.setCoordinateY(y);
                        cd.setCoordinateZ(z);
                        QueryWrapper<Jslcddy> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("station_code",cd.getStationCode());
                        Jslcddy jslcddy = mapper.getJslcddyService().getOne(queryWrapper);
                        if (jslcddy != null){
                            cd.setId(jslcddy.getId());
                            mapper.getJslcddyService().updateById(cd);
                        }else {
                            mapper.getJslcddyService().save(cd);
                        }
                        log.info("cost:" + (System.currentTimeMillis() - start));

                        count++;
                    }
                } catch (Exception e) {
                    log.warn("", e);
                    log.warn("analyze_fail:[{}]", line);
                }
        }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }
    protected void analyzePslCddy(final List<FileDto> fileInfos) {
        analyze("PSLCDDY", fileInfos, this::analyzePslCddy);
    }
    private void analyzePslCddy(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;
        String[] lines = content.split("\\|\\|");
            for (String line : lines) {
                try {
                    String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                    if (parts.length < 2) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid line: {}", line);
                        continue;
                    }
                    for (int i = 1; i < parts.length; i++) {
                        // 第一个部分处理
                        String[] mines = parts[0].split(";");
                        String mineCode = getDatum(mines, 0);

                        // 第二个部分使用 ';' 分割
                        String[] data = parts[i].split(";");
                        if (data.length < 11) {
                            log.info("data_invalid: [{}]", line);
                            continue;
                        }

                        long start = System.currentTimeMillis();
                        String code = getDatum(data, 0);
                        String location = getDatum(data, 1);
                        String area = getDatum(data, 2);
                        BigDecimal x = getDecimal(data, 3);
                        BigDecimal y = getDecimal(data, 4);
                        BigDecimal z = getDecimal(data, 5);
                        String house = getDatum(data, 6);
                        String name = getDatum(data, 7);
                        BigDecimal efficiency = getDecimal(data, 8);
                        BigDecimal flow = getDecimal(data, 9);
                        String type = getDatum(data, 10);
//                    BigDecimal blue = getDecimal(data, 11);
//                    BigDecimal yellow = getDecimal(data, 12);
//                    BigDecimal orange = getDecimal(data, 13);
//                    BigDecimal red = getDecimal(data, 14);
//                    BigDecimal max = getDecimal(data, 15);
                        String date = getDatum(data, 11);
                        Pslcddy cd = new Pslcddy();
                        if (data != null) {
                            Date date1 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            date1 = sdf.parse(date);
                            cd.setInstallationDate(date1);
                        }

                        cd.setStationCode(code);
                        cd.setEquipmentPosition(location);
                        cd.setCoverageArea(area);
                        cd.setCoordinateX(x);
                        cd.setCoordinateY(y);
                        cd.setCoordinateZ(z);
                        cd.setPumpHouse(house);
                        cd.setPumpName(name);
                        cd.setPumpEfficiency(efficiency);
                        cd.setRatedFlow(flow);
                        cd.setPumpType(type);
//                    cd.setDisplacementWarningBlue(blue);
//                    cd.setDisplacementWarningYellow(yellow);
//                    cd.setDisplacementWarningOrange(orange);
//                    cd.setDisplacementWarningRed(red);
//                    cd.setMaxValue(max);

                        cd.setStationMine(mineCode);
                        QueryWrapper<Pslcddy> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("station_code",cd.getStationCode());
                        Pslcddy pslcddy = mapper.getPslcddyService().getOne(queryWrapper);
                        if (pslcddy != null){
                            cd.setId(pslcddy.getId());
                            mapper.getPslcddyService().updateById(cd);
                        }else {
                            mapper.getPslcddyService().save(cd);
                        }
                        log.info("cost:" + (System.currentTimeMillis() - start));

                        count++;
                    }
                } catch (Exception e) {
                    log.warn("", e);
                    log.warn("analyze_fail:[{}]", line);
                }
            }

        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }
    protected void analyzeYslCddy(final List<FileDto> fileInfos) {
        analyze("YSLCDDY", fileInfos, this::analyzeYslCddy);
    }
    private void analyzeYslCddy(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;
        String[] lines = content.split("\\|\\|");
            for (String line : lines) {
                try {
                    String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                    if (parts.length < 2) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid line: {}", line);
                        continue;
                    }
                    for (int i = 1; i < parts.length; i++) {
                        // 第一个部分处理
                        String[] mines = parts[0].split(";");
                        String mineCode = getDatum(mines, 0);

                        // 第二个部分使用 ';' 分割
                        String[] data = parts[i].split(";");

                        if (data.length < 8) {
                            log.info("data_invalid: [{}]", line);
                            continue;
                        }
                        long start = System.currentTimeMillis();
                        String code = getDatum(data, 0);
                        String location = getDatum(data, 1);
                        String area = getDatum(data, 2);
                        String type = getDatum(data, 3);
                        String unit = getDatum(data, 4);
                        BigDecimal x = getDecimal(data, 5);
                        BigDecimal y = getDecimal(data, 6);
                        BigDecimal z = getDecimal(data, 7);
                        String date = getDatum(data, 8);
                        Yslcddy cd = new Yslcddy();
                        if (date != null) {
                            Date date1 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                            date1 = sdf.parse(date);
                            cd.setInstallationDate(date1);
                        }
                        cd.setStationCode(code);
                        cd.setEquipmentPosition(location);
                        cd.setCoverageArea(area);
                        cd.setSensorType(type);
                        cd.setUnit(unit);
                        cd.setCoordinateX(x);
                        cd.setCoordinateY(y);
                        cd.setCoordinateZ(z);
                        cd.setStationMine(mineCode);
                        QueryWrapper<Yslcddy> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("station_code",cd.getStationCode());
                        Yslcddy yslcddy = mapper.getYslcddyService().getOne(queryWrapper);
                        if (yslcddy != null){
                            cd.setId(yslcddy.getId());
                            mapper.getYslcddyService().updateById(cd);
                        }else {
                            mapper.getYslcddyService().save(cd);
                        }
                        log.info("cost:" + (System.currentTimeMillis() - start));

                        count++;
                    }
                } catch (Exception e) {
                    log.warn("", e);
                    log.warn("analyze_fail:[{}]", line);
                }
            }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }
    private void analyzeCdssFile(List<FileDto> FileDtos) {
        List<FileDto> FileDto = FileDtos.stream()
                .filter(f -> StringUtils.hasLength(f.getFileName()) && f.getFileName().length() > 18)
                .sorted(Comparator.comparing(f -> f.getFileName().substring(f.getFileName().length() - 18)))
                .collect(Collectors.toList());

        Stream.of((Consumer<List<FileDto>>) this::analyzeCgkCdss,
                this::analyzeJslCdss,
                this::analyzePslCdss,
                this::analyzeYslCdss,
                this::analyzeDbcxCdss,
                this::analyzeCsCdss,
                this::analyzeDbsCdss,
                this::analyzeWzCdss,
                this::analyzeSbCdss
        ).parallel().forEach(a -> tryAnalyze(a, FileDto));
    }

    private void analyzeSbCdss(List<FileDto> fileInfos) {
        analyze("SBCDSS", fileInfos, this::analyzeSbCdss);
    }

    private void analyzeSbCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    if (data.length < 5) {
                        log.info("data_invalid: [{}]", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String name = getDatum(data, 1);
                    String star = getDatum(data, 2);
                    String end = getDatum(data, 3);
                    String pump = getDatum(data, 4);
                    String date = getDatum(data, 5);
                    Sbcdss cd = new Sbcdss();
                    if (pump != null) {
                        int pump1 = Integer.parseInt(pump);
                        cd.setSwitchPump(pump1);
                    }
                    if (star != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date1 = sdf.parse(star);
                        cd.setStartTime(date1);
                    }
                    if (end != null) {
                        Date date2 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date2 = sdf.parse(end);
                        cd.setEndTime(date2);
                    }
                    if (date != null) {
                        Date date3 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date3 = sdf.parse(date);
                        cd.setDataTime(date3);
                    }
                    cd.setStationCode(code);
                    cd.setPumpName(name);
                    cd.setStationMine(mineCode);
                    QueryWrapper<Sbcdss> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code", cd.getStationCode()).eq("data_time", cd.getDataTime());
                    Sbcdss sbcdss = mapper.getSbcdssService().getOne(queryWrapper);
                    if (sbcdss != null) {
                        cd.setId(sbcdss.getId());
                        mapper.getSbcdssService().updateById(cd);
                    } else {
                        mapper.getSbcdssService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeCsCdss(List<FileDto> fileInfos) {
        analyze("CSCDSS", fileInfos, this::analyzeCsCdss);
    }

    private void analyzeCsCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    if (data.length < 5) {
                        log.info("data_invalid: [{}]", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String location = getDatum(data, 1);
                    String status = getDatum(data, 2);
                    BigDecimal value = getDecimal(data, 3);
                    String unit = getDatum(data, 4);
                    String date = getDatum(data, 5);
                    Cscdss cd = new Cscdss();
                    if (status != null) {
                        int n = Integer.parseInt(status);
                        String s = Integer.toBinaryString(n);
                        while (s.length() < 8) {
                            s = "0" + s;
                        }
                        String status1 = getStatus(s);
                        cd.setStationStatus(s);
                        if (!"正常".equals(status1)) {
                            Csyj csyj = new Csyj();
                            if (date != null) {
                                Date date2 = null;
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                date2 = sdf.parse(date);
                                csyj.setAlarmTime(date2);
                            }
                            csyj.setStationCode(code);
                            csyj.setStationMine(mineCode);
                            csyj.setAlarmStatus("1");
                            mapper.getCsyjService().save(csyj);
                        }
                    }
                    if (date != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date1 = sdf.parse(date);
                        cd.setDataTime(date1);
                    }
                    cd.setStationCode(code);
                    cd.setEquipmentPosition(location);
                    cd.setDrainageAmount(value);
                    cd.setUnit(unit);
                    cd.setStationMine(mineCode);
                    QueryWrapper<Cscdss> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code", cd.getStationCode()).eq("data_time", cd.getDataTime());
                    Cscdss cscdss = mapper.getCscdssService().getOne(queryWrapper);
                    if (cscdss != null) {
                        cd.setId(cscdss.getId());
                        mapper.getCscdssService().updateById(cd);
                    } else {
                        mapper.getCscdssService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeWzCdss(List<FileDto> fileInfos) {
        analyze("WZCDSS", fileInfos, this::analyzeWzCdss);
    }

    private void analyzeWzCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    if (data.length < 11) {
                        log.info("data_invalid: [{}]", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String event = getDatum(data, 0);
                    String no = getDatum(data, 1);
                    BigDecimal x = getDecimal(data, 2);
                    BigDecimal y = getDecimal(data, 3);
                    BigDecimal z = getDecimal(data, 4);
                    BigDecimal energy = getDecimal(data, 5);
                    BigDecimal tude = getDecimal(data, 6);
                    String strtum = getDatum(data, 7);
                    BigDecimal maxTude = getDecimal(data, 8);
                    BigDecimal avgTude = getDecimal(data, 9);
                    BigDecimal frequency = getDecimal(data, 10);
                    String date = getDatum(data, 11);
                    String conclusion = getDatum(data, 12);
                    Wzcdss cd = new Wzcdss();
                    if (date != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date1 = sdf.parse(date);
                        cd.setOccurredTime(date1);
                    }
                    cd.setEventCode(event);
                    cd.setRecordChannelNo(no);
                    cd.setCoordinateX(x);
                    cd.setCoordinateY(y);
                    cd.setCoordinateZ(z);
                    cd.setSeismicEnergy(energy);
                    cd.setMagnitude(tude);
                    cd.setMicroseismicStratum(strtum);
                    cd.setMaxAmplitude(maxTude);
                    cd.setAverageAmplitude(avgTude);
                    cd.setMicroseismicFrequency(frequency);
                    cd.setAnalysisConclusion(conclusion);
                    cd.setStationMine(mineCode);
                    QueryWrapper<Wzcdss> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code", cd.getStationCode()).eq("occurred_time", cd.getOccurredTime());
                    Wzcdss wzcdss = mapper.getWzcdssService().getOne(queryWrapper);
                    if (wzcdss != null) {
                        cd.setId(wzcdss.getId());
                        mapper.getWzcdssService().updateById(cd);
                    } else {
                        mapper.getWzcdssService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeDbsCdss(List<FileDto> fileInfos) {
        analyze("DBSCDSS", fileInfos, this::analyzeDbsCdss);
    }

    private void analyzeDbsCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    if (data.length < 5) {
                        log.info("data_invalid: [{}]", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String type = getDatum(data, 1);
                    String status = getDatum(data, 2);
                    BigDecimal value = getDecimal(data, 3);
                    String unit = getDatum(data, 4);
                    String date = getDatum(data, 5);
                    Dbscdss cd = new Dbscdss();
                    cd.setSensorType(type);
                    if (status != null) {
                        int n = Integer.parseInt(status);
                        String s = Integer.toBinaryString(n);
                        while (s.length() < 8) {
                            s = "0" + s;
                        }
                        String status1 = getStatus(s);
                        cd.setStationStatus(s);
                        if (!"正常".equals(status1)) {
                            Dbsyj dbsyj = new Dbsyj();
                            if (date != null) {
                                Date date2 = null;
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                date2 = sdf.parse(date);
                                dbsyj.setAlarmTime(date2);
                            }
                            dbsyj.setStationCode(code);
                            dbsyj.setStationMine(mineCode);
                            dbsyj.setAlarmStatus("1");
                            mapper.getDbsyjService().save(dbsyj);
                        }
                    }
                    if (date != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date1 = sdf.parse(date);
                        cd.setMonitorTime(date1);
                    }
                    cd.setStationCode(code);
                    cd.setValue(value);
                    cd.setUnit(unit);
                    cd.setStationMine(mineCode);
                    QueryWrapper<Dbscdss> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code", cd.getStationCode()).eq("monitor_time", cd.getMonitorTime());
                    Dbscdss dbscdss = mapper.getDbscdssService().getOne(queryWrapper);
                    if (dbscdss != null) {
                        cd.setId(dbscdss.getId());
                        mapper.getDbscdssService().updateById(cd);
                    } else {
                        mapper.getDbscdssService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeDbcxCdss(List<FileDto> fileInfos) {
        analyze("DBCXCDSS", fileInfos, this::analyzeDbcxCdss);
    }
    private void analyzeDbcxCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                if (parts.length < 2) {
                    // 如果字段数量不足，跳过该行
                    log.warn("Invalid line: {}", line);
                    continue;
                }
                for (int i = 1; i < parts.length; i++) {
                    // 第一个部分处理
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);
                    // 第二个部分使用 ';' 分割
                    String[] data = parts[i].split(";");
                    if (data.length < 5) {
                        log.info("data_invalid: [{}]", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String area = getDatum(data, 1);
                    String no = getDatum(data, 2);
                    String status = getDatum(data, 3);
                    BigDecimal x = getDecimal(data, 4);
                    BigDecimal y = getDecimal(data, 5);
                    BigDecimal z = getDecimal(data, 6);
                    String date = getDatum(data, 7);
                    Dbcxcdss cd = new Dbcxcdss();
                    cd.setCoordinateX(x);
                    cd.setCoordinateY(y);
                    cd.setCoordinateZ(z);
                    if (status != null) {
                        int n = Integer.parseInt(status);
                        String s = Integer.toBinaryString(n);
                        while (s.length() < 8) {
                            s = "0" + s;
                        }
                        String status1 = getStatus(s);
                        cd.setStationStatus(s);
                        if (!"正常".equals(status1)) {
                            Dbcxyj dbcxyj = new Dbcxyj();
                            if (date != null) {
                                Date date2 = null;
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                date2 = sdf.parse(date);
                                dbcxyj.setAlarmTime(date2);
                            }
                            dbcxyj.setStationCode(code);
                            dbcxyj.setStationMine(mineCode);
                            dbcxyj.setAlarmStatus("1");
                            mapper.getDbcxyjService().save(dbcxyj);
                        }
                    }
                    if (date != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date1 = sdf.parse(date);
                        cd.setDataTime(date1);
                    }
                    cd.setStationCode(code);
                    cd.setRegionName(area);
                    cd.setPileCode(no);
                    cd.setStationMine(mineCode);
                    QueryWrapper<Dbcxcdss> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code", cd.getStationCode()).eq("data_time", cd.getDataTime());
                    Dbcxcdss dbcxcdss = mapper.getDbcxcdssService().getOne(queryWrapper);
                    if (dbcxcdss != null) {
                        cd.setId(dbcxcdss.getId());
                        mapper.getDbcxcdssService().updateById(cd);
                    } else {
                        mapper.getDbcxcdssService().save(cd);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeCgkCdss(final List<FileDto> fileInfos) {
        analyze("CGKCDSS", fileInfos, this::analyzeCgkCdss);
    }
    private void analyzeCgkCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");

            for (String line : lines) {
                try {
                    String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                    if (parts.length < 2) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid line: {}", line);
                        continue;
                    }
                    for (int i = 1; i < parts.length; i++) {
                        // 第一个部分处理
                        String[] mines = parts[0].split(";");
                        String mineCode = getDatum(mines, 0);
                        // 第二个部分使用 ';' 分割
                        String[] data = parts[i].split(";");
                        if (data.length < 4) {
                            log.info("data_invalid: [{}]", line);
                            continue;
                        }

                        long start = System.currentTimeMillis();
                        String code = getDatum(data, 0);
//                    String type = getDatum(data, 1);
//                    String location = getDatum(data,2);
                        String status = getDatum(data, 1);
                        BigDecimal level = getDecimal(data, 2);
                        BigDecimal temp = getDecimal(data, 3);
//                    String levelUnit = getDatum(data, 6);
//                    String tempUnit = getDatum(data, 7);
                        String date = getDatum(data, 4);
                        Cgkcdss cd = new Cgkcdss();
                        if (status != null) {
                            int n = Integer.parseInt(status);
                            String s = Integer.toBinaryString(n);
                            while (s.length() < 8) {
                                s = "0" + s;
                            }
                            cd.setPointStatus(s);
                        }
                        if (date != null) {
                            Date date1 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            date1 = sdf.parse(date);
                            cd.setMonitorTime(date1);
                        }
                        cd.setStationCode(code);
//                    cd.setSensorType(type);
//                    cd.setLocation(location);
                        cd.setWaterLevel(level);
                        cd.setWaterTemperature(temp);
//                    cd.setWaterLevelUnit(levelUnit);
//                    cd.setWaterTemperatureUnit(tempUnit);
                        cd.setOrgCode(mineCode);
                        QueryWrapper<Cgkcdss> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("station_code",cd.getStationCode()).eq("monitor_time",cd.getMonitorTime());
                        Cgkcdss cgkcdss = mapper.getCgkcdssService().getOne(queryWrapper);
                        if (cgkcdss != null){
                            cd.setId(cgkcdss.getId());
                            mapper.getCgkcdssService().updateById(cd);
                        }else {
                            mapper.getCgkcdssService().save(cd);
                        }
                        log.info("cost:" + (System.currentTimeMillis() - start));

                        count++;
                    }
                } catch (Exception e) {
                    log.warn("", e);
                    log.warn("analyze_fail:[{}]", line);
                }
            }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeJslCdss(final List<FileDto> fileInfos) {
        analyze("JSLCDSS", fileInfos, this::analyzeJslCdss);
    }
    private void analyzeJslCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");
            for (String line : lines) {
                try {
                    String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                    if (parts.length < 2) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid line: {}", line);
                        continue;
                    }
                    for (int i = 1; i < parts.length; i++) {
                        // 第一个部分处理
                        String[] mines = parts[0].split(";");
                        String mineCode = getDatum(mines, 0);

                        // 第二个部分使用 ';' 分割
                        String[] data = parts[i].split(";");
                        if (data.length < 5) {
                            log.info("data_invalid: [{}]", line);
                            continue;
                        }

                        long start = System.currentTimeMillis();
                        String code = getDatum(data, 0);
                        String clear = getDatum(data, 1);
                        String ce = getDatum(data, 2);
                        String time = getDatum(data, 3);
                        String status = getDatum(data, 4);
                        BigDecimal value = getDecimal(data, 5);
                        Jslcdss cd = new Jslcdss();
                        if (clear != null) {
                            Date date1 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            date1 = sdf.parse(clear);
                            cd.setClearTime(date1);
                        }
                        if (ce != null) {
                            Date date2 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            date2 = sdf.parse(ce);
                            cd.setMeasureTime(date2);
                        }
                        if (time != null) {
                            Date date3 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            date3 = sdf.parse(time);
                            cd.setMonitorTime(date3);
                        }
                        cd.setStationCode(code);
                        cd.setValue(value);
                        cd.setStationMine(mineCode);
                        if (status != null) {
                            int n = Integer.parseInt(status);
                            String s = Integer.toBinaryString(n);
                            while (s.length() < 8) {
                                s = "0" + s;
                            }
                            status = getStatus(s);
                            cd.setStationStatus(s);
                            if (!"正常".equals(status)) {
                                Jslyj jslyj = new Jslyj();
                                if (ce != null) {
                                    Date date2 = null;
                                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                    date2 = sdf.parse(ce);
                                    jslyj.setAlarmTime(date2);
                                }
                                jslyj.setStationCode(code);
                                jslyj.setStationMine(mineCode);
                                jslyj.setAlarmStatus("1");
                                QueryWrapper<Jslyj> queryWrapper = new QueryWrapper<>();
                                queryWrapper.eq("station_code",jslyj.getStationCode()).eq("alarm_time",jslyj.getAlarmTime());
                                Jslyj jslyj1 = mapper.getJslyjService().getOne(queryWrapper);
                                if (jslyj1 != null){
                                    cd.setId(jslyj1.getId());
                                    mapper.getJslyjService().updateById(jslyj);
                                }else {
                                    mapper.getJslyjService().save(jslyj);
                                }
                            }
                        }
                        QueryWrapper<Jslcdss> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("station_code",cd.getStationCode()).eq("monitor_time",cd.getMonitorTime());
                        Jslcdss jslcdss = mapper.getJslcdssService().getOne(queryWrapper);
                        if (jslcdss != null){
                            cd.setId(jslcdss.getId());
                            mapper.getJslcdssService().updateById(cd);
                        }else {
                            mapper.getJslcdssService().save(cd);
                        }
                        log.info("cost:" + (System.currentTimeMillis() - start));

                        count++;
                    }
                } catch (Exception e) {
                    log.warn("", e);
                    log.warn("analyze_fail:[{}]", line);
                }
            }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzePslCdss(final List<FileDto> fileInfos) {
        analyze("PSLCDSS", fileInfos, this::analyzePslCdss);
    }
    private void analyzePslCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");
            for (String line : lines) {
                try {
                    String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                    if (parts.length < 2) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid line: {}", line);
                        continue;
                    }
                    for (int i = 1; i < parts.length; i++) {
                        // 第一个部分处理
                        String[] mines = parts[0].split(";");
                        String mineCode = getDatum(mines, 0);

                        // 第二个部分使用 ';' 分割
                        String[] data = parts[i].split(";");
                        if (data.length < 4) {
                            log.info("data_invalid: [{}]", line);
                            continue;
                        }
                        long start = System.currentTimeMillis();
                        String code = getDatum(data, 0);
                        String location = getDatum(data, 1);
                        String status = getDatum(data, 2);
                        BigDecimal value = getDecimal(data, 3);
                        String time = getDatum(data, 4);
                        Pslcdss cd = new Pslcdss();
                        if (time != null) {
                            Date date1 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            date1 = sdf.parse(time);
                            cd.setMonitorTime(date1);
                        }
                        cd.setStationCode(code);
                        cd.setValue(value);
                        cd.setLocation(location);
                        cd.setStationMine(mineCode);
                        if (status != null) {
                            int n = Integer.parseInt(status);
                            String s = Integer.toBinaryString(n);
                            while (s.length() < 8) {
                                s = "0" + s;
                            }
                            status = getStatus(s);
                            cd.setStationStatus(s);
                            if (!"正常".equals(status)) {
                                Pslcdyc pslcdyc = new Pslcdyc();
                                Pslyj pslyj = new Pslyj();
                                pslcdyc.setStationCode(code);
                                pslcdyc.setEquipmentPosition(location);
                                pslcdyc.setAbnormalType(status);
                                if (time != null) {
                                    Date date1 = null;
                                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                    date1 = sdf.parse(time);
                                    cd.setMonitorTime(date1);
                                    pslcdyc.setDataTime(date1);
                                    pslyj.setAlarmTime(date1);
                                }
                                pslcdyc.setStationMine(mineCode);
                                QueryWrapper<Pslcdyc> queryWrapper = new QueryWrapper<>();
                                queryWrapper.eq("station_code",pslcdyc.getStationCode()).eq("data_time",pslcdyc.getDataTime());
                                Pslcdyc pslcdyc1 = mapper.getPslcdycService().getOne(queryWrapper);
                                if (pslcdyc1 != null){
                                    cd.setId(pslcdyc1.getId());
                                    mapper.getPslcdycService().updateById(pslcdyc);
                                }else {
                                    mapper.getPslcdycService().save(pslcdyc);
                                }
                                pslyj.setStationCode(code);
                                pslyj.setStationMine(mineCode);
                                pslyj.setAlarmStatus("1");
                                QueryWrapper<Pslyj> queryWrapper1 = new QueryWrapper<>();
                                queryWrapper1.eq("point_code",pslyj.getStationCode()).eq("alarm_time",pslyj.getAlarmTime());
                                Pslyj pslyj1 = mapper.getPslyjService().getOne(queryWrapper1);
                                if (pslyj1 != null){
                                    cd.setId(pslyj1.getId());
                                    mapper.getPslyjService().updateById(pslyj);
                                }else {
                                    mapper.getPslyjService().save(pslyj);
                                }
                            }
                        }
                        QueryWrapper<Pslcdss> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("station_code",cd.getStationCode()).eq("monitor_time",cd.getMonitorTime());
                        Pslcdss pslcdss = mapper.getPslcdssService().getOne(queryWrapper);
                        if (pslcdss != null){
                            cd.setId(pslcdss.getId());
                            mapper.getPslcdssService().updateById(cd);
                        }else {
                            mapper.getPslcdssService().save(cd);
                        }
                        log.info("cost:" + (System.currentTimeMillis() - start));

                        count++;
                    }
                } catch (Exception e) {
                    log.warn("", e);
                    log.warn("analyze_fail:[{}]", line);
                }
            }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeYslCdss(final List<FileDto> fileInfos) {
        analyze("YSLCDSS", fileInfos, this::analyzeYslCdss);
    }
    private void analyzeYslCdss(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");
            for (String line : lines) {
                try {
                    String[] parts = line.split("~", -1); // 使用 -1 参数确保空字段也被保留
                    if (parts.length < 2) {
                        // 如果字段数量不足，跳过该行
                        log.warn("Invalid line: {}", line);
                        continue;
                    }
                    for (int i = 1; i < parts.length; i++) {
                        // 第一个部分处理
                        String[] mines = parts[0].split(";");
                        String mineCode = getDatum(mines, 0);

                        // 第二个部分使用 ';' 分割
                        String[] data = parts[i].split(";");
                        if (data.length < 3) {
                            log.info("data_invalid: [{}]", line);
                            continue;
                        }
                        long start = System.currentTimeMillis();
                        String code = getDatum(data, 0);
//                    String type = getDatum(data, 1);
//                    String location = getDatum(data, 2);
                        String status = getDatum(data, 1);
                        String value = getDatum(data, 2);
//                    String unit = getDatum(data, 5);
                        String time = getDatum(data, 3);
                        Yslcdss cd = new Yslcdss();
                        if (time != null) {
                            Date date1 = null;
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            date1 = sdf.parse(time);
                            cd.setMonitorTime(date1);
                        }
//                    cd.setSensorType(type);
                        cd.setPointCode(code);
//                    cd.setLocation(location);
//                    cd.setUnit(unit);
                        cd.setValue(value);
                        cd.setStationMine(mineCode);
                        if (status != null) {
                            int n = Integer.parseInt(status);
                            String s = Integer.toBinaryString(n);
                            while (s.length() < 8) {
                                s = "0" + s;
                            }
                            status = getStatus(s);
                            cd.setPointStatus(s);
                            if (!"正常".equals(status)) {
                                Yslyj yslyj = new Yslyj();
                                if (time != null) {
                                    Date date1 = null;
                                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                    date1 = sdf.parse(time);
                                    yslyj.setAlarmTime(date1);
                                }
                                yslyj.setStationCode(code);
                                yslyj.setStationMine(mineCode);
                                yslyj.setAlarmStatus("1");
                                QueryWrapper<Yslyj> queryWrapper = new QueryWrapper<>();
                                queryWrapper.eq("point_code",yslyj.getStationCode()).eq("alarm_time",yslyj.getAlarmTime());
                                Yslyj yslyj1 = mapper.getYslyjService().getOne(queryWrapper);
                                if (yslyj1 != null){
                                    cd.setId((yslyj1.getId()));
                                    mapper.getYslyjService().updateById(yslyj);
                                }else {
                                    mapper.getYslyjService().save(yslyj);
                                }
                            }
                        }
                        QueryWrapper<Yslcdss> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("point_code",cd.getPointCode()).eq("monitor_time",cd.getMonitorTime());
                        Yslcdss yslcdss = mapper.getYslcdssService().getOne(queryWrapper);
                        if (yslcdss != null){
                            cd.setId(yslcdss.getId());
                            mapper.getYslcdssService().updateById(cd);
                        }else {
                            mapper.getYslcdssService().save(cd);
                        }
                        log.info("cost:" + (System.currentTimeMillis() - start));

                        count++;
                    }
                } catch (Exception e) {
                    log.warn("", e);
                    log.warn("analyze_fail:[{}]", line);
                }
            }
        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    private void analyzeCdycFile(List<FileDto> FileDtos) {
        List<FileDto> FileDto = FileDtos.stream()
                .filter(f -> StringUtils.hasLength(f.getFileName()) && f.getFileName().length() > 18)
                .sorted(Comparator.comparing(f -> f.getFileName().substring(f.getFileName().length() - 18)))
                .collect(Collectors.toList());

        Stream.of((Consumer<List<FileDto>>) this::analyzeCgkCdyc,
                this::analyzeJslCdyc,
                this::analyzePslCdyc,
                this::analyzeYslCdyc
        ).parallel().forEach(a -> tryAnalyze(a, FileDto));
    }

    protected void analyzeCgkCdyc(final List<FileDto> fileInfos) {
        analyze("CGKCDYC", fileInfos, this::analyzeCgkCdyc);
    }
    private void analyzeCgkCdyc(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~",-1);
                if (parts.length < 2) {
                    log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
                    return;
                }
                for (int i = 1; i < parts.length; i++) {
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);

                    String[] data = parts[i].split(";");
                    if (data.length < 5) {
                        log.info("data_invalid: [{}]", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String type = getDatum(data, 1);
                    String location = getDatum(data, 2);
                    String status = getDatum(data, 3);
                    String info = getDatum(data, 4);
                    String time = getDatum(data, 5);
                    String level = getDatum(data, 6);
                    int level1 = Integer.parseInt(level);
                    String reason = getDatum(data, 7);
                    String per = getDatum(data, 8);
                    String end = getDatum(data, 9);
                    String update = getDatum(data, 10);
                    Cgkcdyc cgkcdyc = new Cgkcdyc();
                    Cgkyj cgkyj = new Cgkyj();
                    if (time != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date1 = sdf.parse(time);
                        cgkcdyc.setStartTime(date1);
                        cgkyj.setAlarmTime(date1);
                    }
                    if (end != null) {
                        Date date2 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date2 = sdf.parse(end);
                        cgkcdyc.setEndTime(date2);
                    }
                    if (update != null) {
                        Date date3 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date3 = sdf.parse(update);
                        cgkcdyc.setDataTime(date3);
                    }
                    if (status != null) {
                        int n = Integer.parseInt(status);
                        String s = Integer.toBinaryString(n);
                        while (s.length() < 8) {
                            s = "0" + s;
                        }
                        cgkcdyc.setAbnormalType(s);
                    }
                    cgkcdyc.setStationCode(code);
                    cgkcdyc.setStationMine(mineCode);
                    cgkcdyc.setSensorType(type);
                    cgkcdyc.setEquipmentPosition(location);
                    cgkcdyc.setAbnormalContent(info);
                    cgkcdyc.setWarnLevel(level1);
                    cgkcdyc.setAbnormalReason(reason);
                    cgkcdyc.setAbnormalKeyboarder(per);
                    QueryWrapper<Cgkcdyc> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code",cgkcdyc.getStationCode()).eq("data_time",cgkcdyc.getDataTime());
                    Cgkcdyc cgkcdyc1 = mapper.getCgkcdycService().getOne(queryWrapper);
                    if (cgkcdyc1 != null){
                        cgkcdyc.setId(cgkcdyc1.getId());
                        mapper.getCgkcdycService().updateById(cgkcdyc);
                    }else {
                        mapper.getCgkcdycService().save(cgkcdyc);
                    }
                    cgkyj.setAlarmContent(info);
                    cgkyj.setAlarmStatus("1");
                    cgkyj.setStationCode(code);
                    cgkyj.setStationMine(mineCode);
                    QueryWrapper<Cgkyj> queryWrapper1 = new QueryWrapper<>();
                    queryWrapper1.eq("station_code",cgkyj.getStationCode()).eq("alarm_time",cgkyj.getAlarmTime());
                    Cgkyj cgkyj1 = mapper.getCgkyjService().getOne(queryWrapper1);
                    if (cgkyj1 != null){
                        cgkyj.setId(cgkyj1.getId());
                        mapper.getCgkyjService().updateById(cgkyj);
                    }else {
                        mapper.getCgkyjService().save(cgkyj);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));

                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }

        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeJslCdyc(final List<FileDto> fileInfos) {
        analyze("JSLCDYC", fileInfos, this::analyzeJslCdyc);
    }
    private void analyzeJslCdyc(final List<String> matches, final String content, FileDto fileInfo) {
        fileInfo.setAnalyzed(true);
    }

    protected void analyzePslCdyc(final List<FileDto> fileInfos) {
        analyze("PSLCDYC", fileInfos, this::analyzePslCdyc);
    }
    private void analyzePslCdyc(final List<String> matches, final String content, FileDto fileInfo) {
        long begin = System.currentTimeMillis();
        int count = 0;

        String[] lines = content.split("\\|\\|");

        for (String line : lines) {
            try {
                String[] parts = line.split("~",-1);
                if (parts.length < 2) {
                    log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
                    return;
                }
                for (int i = 1; i < parts.length; i++) {
                    String[] mines = parts[0].split(";");
                    String mineCode = getDatum(mines, 0);

                    String[] data = parts[i].split(";");
                    if (data.length < 5) {
                        log.info("data_invalid: [{}]", line);
                        continue;
                    }
                    long start = System.currentTimeMillis();
                    String code = getDatum(data, 0);
                    String location = getDatum(data, 1);
                    String type = getDatum(data, 2);
                    String info = getDatum(data, 3);
                    String time = getDatum(data, 4);
                    String level = getDatum(data, 5);
                    int level1 = Integer.parseInt(level);
                    String reason = getDatum(data, 6);
                    String per = getDatum(data, 7);
                    String end = getDatum(data, 8);
                    String update = getDatum(data, 9);
                    Pslcdyc pslcdyc = new Pslcdyc();
                    Pslyj pslyj = new Pslyj();
                    if (time != null) {
                        Date date1 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date1 = sdf.parse(time);
                        pslcdyc.setStartTime(date1);
                        pslyj.setAlarmTime(date1);
                    }
                    if (end != null) {
                        Date date2 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date2 = sdf.parse(end);
                        pslcdyc.setEndTime(date2);
                    }
                    if (update != null) {
                        Date date3 = null;
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        date3 = sdf.parse(update);
                        pslcdyc.setDataTime(date3);
                    }
                    if (type != null) {
                        int n = Integer.parseInt(type);
                        String s = Integer.toBinaryString(n);
                        while (s.length() < 8) {
                            s = "0" + s;
                        }
                        pslcdyc.setAbnormalType(s);
                    }
                    pslcdyc.setStationCode(code);
                    pslcdyc.setStationMine(mineCode);
                    pslcdyc.setEquipmentPosition(location);
                    pslcdyc.setAbnormalContent(info);
                    pslcdyc.setWarnLevel(level1);
                    pslcdyc.setAbnormalReason(reason);
                    pslcdyc.setAbnormalKeyboarder(per);
                    QueryWrapper<Pslcdyc> queryWrapper1 = new QueryWrapper<>();
                    queryWrapper1.eq("station_code",pslcdyc.getStationCode()).eq("data_time",pslcdyc.getDataTime());
                    Pslcdyc pslcdyc1 = mapper.getPslcdycService().getOne(queryWrapper1);
                    if (pslcdyc1 != null){
                        pslcdyc.setId(pslcdyc1.getId());
                        mapper.getPslcdycService().updateById(pslcdyc);
                    }else {
                        mapper.getPslcdycService().save(pslcdyc);
                    }
                    pslyj.setAlarmContent(info);
                    pslyj.setAlarmStatus("1");
                    pslyj.setStationCode(code);
                    pslyj.setStationMine(mineCode);
                    QueryWrapper<Pslyj> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("station_code",pslyj.getStationCode()).eq("alarm_time",pslyj.getAlarmTime());
                    Pslyj pslyj1 = mapper.getPslyjService().getOne(queryWrapper);
                    if (pslyj1 != null){
                        pslyj.setId(pslyj1.getId());
                        mapper.getPslyjService().updateById(pslyj);
                    }else {
                        mapper.getPslyjService().save(pslyj);
                    }
                    log.info("cost:" + (System.currentTimeMillis() - start));
                    count++;
                }
            } catch (Exception e) {
                log.warn("", e);
                log.warn("analyze_fail:[{}]", line);
            }
        }

        log.info("end_collect: [{}-{}] [{}]", fileInfo.getFileName(), count, System.currentTimeMillis() - begin);
        fileInfo.setAnalyzed(true);
    }

    protected void analyzeYslCdyc(final List<FileDto> fileInfos) {
        analyze("YSLCDYC", fileInfos, this::analyzeYslCdyc);
    }
    private void analyzeYslCdyc(final List<String> matches, final String content, FileDto fileInfo) {
        fileInfo.setAnalyzed(true);
    }
}
